//
//  EmoticonPackage.swift
//  EmoticonKeyBoard
//
//  Created by yang on 15/11/21.
//  Copyright © 2015年 yang. All rights reserved.
//

import UIKit

class EmoticonPackage: NSObject {
    //表情数组 
    lazy var emoticonList = [Emoticon]()
    
    //表情分组的包名
    var id:String?
    //表情分组的中文名称
    var group_name_cn:String?
    
    init(id:String,group_name_cn:String,emoticons:[[String:String]]){
        self.id = id
        self.group_name_cn = group_name_cn
        super.init()
        //表情字典数组转换为模型数组
        var index = 0
        for item in emoticons{
            let e = Emoticon(id: id, dict: item)
            emoticonList.append(e)
            index++

            //添加删除模型
            if index == 20 {
                let deleteEmoticon = Emoticon(isRemove: true)
                emoticonList.append(deleteEmoticon)
                index = 0
            }
            
        }
       //不足21个 补足空表情
         isnsertEmptyEmoticon()
    }
    private func isnsertEmptyEmoticon(){
        let count = emoticonList.count % 21
        if count == 0 {
            return
        }
        for _ in count..<20 {
            let empty = Emoticon(isEmpty: true)
            emoticonList.append(empty)
        }
        let deleteEmoticon = Emoticon(isRemove: true)
        emoticonList.append(deleteEmoticon)
    }
    //重写description
    override var description: String {
        
        return "id = \(id),name = \(group_name_cn)"
    }
}
